from wtforms import SelectField, StringField, DateField
from wtforms.validators import Optional

from apps.forms.base_form import BaseForm


class QuerySystemLogForm(BaseForm):
    module = SelectField('操作模块', validators=[Optional()], coerce=str,
                         render_kw={'class': 'filter-select'},
                         default='')
    operator = StringField('真实姓名', validators=[Optional()],
                           render_kw={"placeholder": "真实姓名", 'class': 'search-input'})
    create_time_start = DateField('创建时间-开始时间', format='%Y-%m-%d',
                                  render_kw={"placeholder": "创建时间-开始时间", 'class': 'search-input'})
    create_time_end = DateField('创建时间-结束时间', format='%Y-%m-%d',
                                render_kw={"placeholder": "创建时间-结束时间", 'class': 'search-input'})

    def __init__(self, *args, **kwargs):
        super(QuerySystemLogForm, self).__init__(*args, **kwargs)
        self.module.choices = self.get_module_list(is_all=True)
